import zipfile, time
import itertools as its
from multiprocessing import Pool


# author = __rianley__<br>
def extractFile(numer):
    password = generate_pwd(numer)  # 拿到生成器对象，密码字典过大，只能用生成器否则一下就把内存撑爆了！
    zFile = zipfile.ZipFile('C:\\Users\\你爹\\Downloads\\Compressed\\第一次兼职经历.7z')  # 打开zip包
    for pwd in password:
        try:
            zFile.extractall(pwd=bytes(pwd, "utf-8"))
            return pwd

        except Exception as e:
            # print(pwd)
            continue


def generate_pwd(numer):  # 生成密码
    words = "1234568790"  # 密码范围：当前表示纯数字范围
    r = its.product(words, repeat=numer)
    for i in r:
        pwd = ''
        for num in i:
            pwd += num
        yield pwd


if __name__ == '__main__':
    p = Pool()  # 开启进程池
    res_list = []  # 定义存放进程的列表
    for i in range(1, 30):  # 设置 随机密码的位数（如果别人的设置的密码）
        res_run = p.apply_async(extractFile, args=(i,))  # res_run = extractFile(zFile,pwd)
        res_list.append(res_run)

    print('正在尝试破解')  # 打印一句提示性的信息

    for kill in res_list:
        data = kill.get()

        if data:
            print('破解成功：密码是：%s' % data)
            exit()